package com.example.gameapplication.bullet;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.example.gameapplication.BaseObject;
import com.example.gameapplication.R;
import com.example.gameapplication.database.DataUtils;
import com.example.gameapplication.plant.MainPlane;

public class WindmillBullet extends BaseObject {
    private final MainPlane mainPlane;
    private Bitmap bullet;
    float angle;//旋转角度
    int r;//旋转半径
    boolean clockwise;//顺时针

    public boolean isClockwise() {
        return clockwise;
    }

    public void setClockwise(boolean clockwise) {
        this.clockwise = clockwise;
    }

    public float getAngle() {
        return angle;
    }

    public void setAngle(float angle) {
        this.angle = angle;
    }

    public int getR() {
        return r;
    }

    public void setR(int r) {
        this.r = r;
    }

    public WindmillBullet(Resources resources, Paint paint) {
        super(resources, paint);
        mainPlane = DataUtils.getmainPlane(resources);
        r = DataUtils.getGameViewWidth() / 5;
    }

    @Override
    public void initBitmap() {
        bullet = BitmapFactory.decodeResource(resources, R.drawable.bullet_triangle);
        object_width = bullet.getWidth();
        object_height = bullet.getHeight();
    }

    @Override
    public void drawSelf(Canvas canvas) {
        setSeat((float) (mainPlane.midx + r * Math.cos(angle * Math.PI / 180)), (float) (mainPlane.midy + r * Math.sin(angle * Math.PI / 180)));
        //画子弹
        canvas.save();
        canvas.rotate(angle, mainPlane.midx, mainPlane.midy);
        canvas.clipRect(leftx, lefty, rightx, righty);
        canvas.drawBitmap(bullet, leftx, lefty, paint);
        canvas.restore();
//        attack(); //调到  DataUtils.runWindmillArrack();
        logic();
    }



    @Override
    public int getLv() {
        return mainPlane.lv;
    }

    private void attack() {
        DataUtils.WindmillAttack(this);
    }

    private void logic() {
        if (clockwise)
            angle +=8;
        else
            angle -=8;
    }

    @Override
    public void dataDestroyed() {

    }
}
